module sdldee.video.palette;

import std.string;

import sdldee.c.sdl;
import sdldee.video.colour;

enum PaletteFlag {
	SDL_LOGPAL = 0x01,
	SDL_PHYSPAL = 0x02
}

class OutOfBoundsException : Exception {
	this(size_t i) {
		super("Index " ~ std.string.toString(i) ~ " is out of bounds");
	}
}

class Palette {
	private SDL_Palette* _palette;
	
	this(SDL_Palette* palette) {
		_palette = palette;
	}
	
	public SDL_Palette* cpalette() {
		return _palette;
	}
	
	public int length() {
		return _palette.ncolors;
	}
	
	public Colour opIndex(size_t index) {
		if(index < 0 || index >= length)
			throw new OutOfBoundsException(index);
		
		return new Colour(&_palette.colors[index]);
	}
	
	public Colour[] toColourArray() {
		Colour[] colours;
		colours.length = length;
		for(int i = 0; i < length; i++)
			colours[i] = this[i];
		return colours;
	}
}
